package com.xmh.ffmpeg;

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
import com.gargoylesoftware.htmlunit.WebClient;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

//@RunWith(SpringJUnit4ClassRunner.class)
//@ContextConfiguration("/spring_bean.xml")
//@Transactional
@Slf4j
public class webReptile {

    @Test
    public void main() throws IOException, InterruptedException {
        final WebClient webClient = new WebClient(BrowserVersion.CHROME);// 新建一个模拟谷歌Chrome浏览器的浏览器客户端对象
        webClient.getOptions().setThrowExceptionOnScriptError(false);// 当JS执行出错的时候是否抛出异常, 这里选择不需要
        webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);// 当HTTP的状态非200时是否抛出异常, 这里选择不需要
        webClient.getOptions().setActiveXNative(false);
        webClient.getOptions().setCssEnabled(false);// 是否启用CSS, 因为不需要展现页面, 所以不需要启用
        webClient.getOptions().setJavaScriptEnabled(true); // 很重要，启用JS
        webClient.setJavaScriptEngine(new MyJavaScriptEngine(webClient));// 自定义JavaScript引擎，有js错误不打印
        webClient.setAjaxController(new NicelyResynchronizingAjaxController());// 很重要，设置支持AJAX


        try {
            webClient.getPage("https://e1v-h.phncdn.com/hls/videos/202001/13/276409191/,720P_4000K,480P_2000K,240P_400K,_276409191.mp4.urlset/seg-80-f1-v1-a1.ts?validfrom=1620967596&validto=1620974796&ip=38.143.3.108&ipa=38.143.3.108&hdl=-1&hash=tdiCXD2wVuhowBXnah6sd%2F1jrbI%3D");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
